package com.nlscan.techhub.catalog.app

import android.annotation.SuppressLint
import android.app.Application
import com.hm.lifecycle.api.ApplicationLifecycleManager
import com.nlscan.qdkit.ui.publico.util.SpUtil
import com.nlscan.ble.util.NLogUtil
import com.nlscan.qdkit.common.core.app.App
import com.nlscan.qdkit.common.core.model.entity.ApplicationInfo
import com.nlscan.ncomgateway.BuildConfig
import com.nlscan.ncomgateway.core.common.CoreApp
import java.text.SimpleDateFormat
import java.util.*

//@HiltAndroidApp
class ExportApp : CoreApp() {
    private val info by lazy {
        ApplicationInfo(
            BuildConfig.DEBUG,
            BuildConfig.APPLICATION_ID,
            BuildConfig.BUILD_TIMESTAMP,
            SpUtil.getInstance().isDebugMode,
            BuildConfig.VERSION_CODE,
            BuildConfig.VERSION_NAME
        )
    }


    @SuppressLint("WrongConstant")
    override fun onCreate() {
        super.onCreate()
        NLogUtil.i("ExportApp onCreate")
        ApplicationLifecycleManager.init()
        ApplicationLifecycleManager.onCreate(this)

//        SpManager.getInstance().init(this)

    }


    override fun onTerminate() {
        super.onTerminate()

        ApplicationLifecycleManager.onTerminate()
    }

    override fun onLowMemory() {
        super.onLowMemory()

        ApplicationLifecycleManager.onLowMemory()
    }

    override fun onTrimMemory(level: Int) {
        super.onTrimMemory(level)

        ApplicationLifecycleManager.onTrimMemory(level)
    }

    override fun getAppInfo(): ApplicationInfo {
        return info
    }

    override fun getAppReportInfo(): String {
        return """
            编译时间 ${
            SimpleDateFormat(
                "yyyy-MM-dd_HH:mm:ss",
                Locale.CHINA
            ).format(Date(BuildConfig.BUILD_TIMESTAMP))
        }
            App application id: ${BuildConfig.APPLICATION_ID}
            App Version Code: ${BuildConfig.VERSION_CODE}
            """.trimIndent()
    }

    companion object {
        var GLOBAL_TAG = "NComGateway"
        var isHidConnMode = false

        fun getContext(): Application {
            return getInstance()
        }

        fun getInstance(): ExportApp {
            return (App.getInstance() as? ExportApp)!!
        }
    }
}